<template>
	<view class="">
		<cu-custom bgColor="bgmain" :isBack="true">
			<view slot="content">商品详情</view>
		</cu-custom>
		<view class="content">

			<image :src="data.image" style="width: 750rpx;" mode="widthFix"></image>
			<view style="width: 720rpx;margin: 8rpx auto;font-size: 32rpx;color: #3c3e41;font-weight: bold;">
				{{data.title}}
			</view>
			<view style="width: 720rpx;display: flex;justify-content: space-between;margin-top: 12rpx;">
				<view class="">
					<!-- <text class="cuIcon-refund"></text> -->
					<image src="/static/jifen.png" style="width: 32rpx;height: 32rpx;"></image>
					<text v-if="data.pay_type == 0" style="font-size:50rpx;color: #1296db;">{{data.integral}}</text>
					<text v-if="data.pay_type == 1" style="font-size:50rpx;color: #1296db;">{{data.price}}</text>
					<text v-if="data.pay_type == 0" style="color: #1296db;font-size: 25rpx;margin-left: 6rpx;">积分</text>
					<text v-if="data.pay_type == 1" style="color: #1296db;font-size: 25rpx;margin-left: 6rpx;">元</text>
				</view>
			</view>
			<view style="width: 720rpx;height: 10rpx;background: #e8ebf5;margin: 18rpx auto;"></view>
			<!-- <view style="width: 720rpx;margin: 8rpx auto;display: flex;align-items: center;">
				<view style="width: 8rpx;height: 32rpx;background: #1296db;border-radius: 8rpx;"></view>
				<view style="font-size: 32rpx;margin-left: 6rpx;color: #3c3e41;">
					商品简介
				</view>
			</view>
			<view style="width: 700rpx;margin: 24rpx auto;height: 1rpx;background: #f1f1f1;">
		
			</view>
			<view style="width: 700rpx;margin: 8rpx auto;font-size: 28rpx;color: #424346;">
				{{data.jianjie}}
			</view> -->
			<!-- <view style="width: 720rpx;height: 10rpx;background: #e8ebf5;margin: 18rpx auto;"></view> -->
			<view style="width: 720rpx;margin: 8rpx auto;display: flex;align-items: center;">
				<view style="width: 8rpx;height: 32rpx;background: #1296db;border-radius: 8rpx;"></view>
				<view style="font-size: 32rpx;margin-left: 6rpx;color: #3c3e41;">
					商品详情
				</view>
			</view>
			<view style="width: 700rpx;margin: 24rpx auto;height: 4rpx;background: #f1f1f1;">

			</view>
			<view style="width: 700rpx;margin: 8rpx auto;font-size: 28rpx;color: #424346;">
				<mp-html :content="data.details"></mp-html>
				<!-- <u-parse :html="data.info" domain="https://jiayou.haoleen.com"></u-parse> -->
			</view>
			<view style="width: 750rpx;height: 160rpx;">

			</view>
			<view v-if="data.pay_type == 0"
				style="width: 750rpx;display: flex;position: fixed;bottom: 0rpx;left: 0rpx;background: white;height: 100rpx;box-shadow: 0 0 23rpx #636363;">
				<view style="width: 500rpx;height: 100rpx;display: flex;align-items: center;margin-left: 16rpx;">
					积分兑换:{{data.integral}}
				</view>
				<view @click="$throttle(duihuan,3000) "
					style="width: 250rpx;height: 100rpx; background: #1296db;color: white;display: flex;align-items: center;justify-content: center;">
					积分兑换
				</view>
			</view>

			<view v-if="data.pay_type == 1"
				style="width: 750rpx;display: flex;position: fixed;bottom: 0rpx;left: 0rpx;background: white;height: 100rpx;box-shadow: 0 0 23rpx #636363;">
				<view style="width: 500rpx;height: 100rpx;display: flex;align-items: center;margin-left: 16rpx;">
					价格:{{data.price}}
				</view>
				<view @click="$throttle(duihuans,3000)"
					style="width: 250rpx;height: 100rpx; background: #1296db;color: white;display: flex;align-items: center;justify-content: center;">
					支付并下载
				</view>
			</view>
		</view>
	</view>


</template>

<script>
	var app = getApp()
	export default {
		data() {
			return {
				data: '',
				userinfo: '',
				id: ''
			}
		},
		onLoad(o) {
			var id = o.id
			var that = this
			this.id = id
			this.getgoodinfo(id)
		},
		onShareAppMessage() {

		},
		onShow() {
			this.getuser()
		},
		methods: {
			getuser() {
				var that = this
				app.globalData.util.request({
					url: 'WechatUser/view',
					data: {
						s_id: uni.getStorageSync('schoolId')
					},
					success(res) {
						if (res.data.status == 200) {
							that.userinfo = res.data.data
							console.log(9939, res)
						}

					}
				}, true)
			},
			duihuans: function() {
				var that = this
				if (this.userinfo) {
					uni.showLoading({
						title:'支付中'
					})
					app.globalData.util.request({

						url: 'Knowledgeorder/add',
						data: {
							s_id: uni.getStorageSync('schoolId'),
							id: that.id,
							type: that.data.pay_type
						},
						success(res) {
							if (res.data.status == 200) {

								console.log('zhifu', res)
								uni.requestPayment({
									...res.data.data.paydata,
									timeStamp:  res.data.data.paydata.signType == 'RSA' ?  res.data.data.paydata.timeStamp.toString() : res.data.data.paydata.timestamp.toString() ,
									success: function(resu) {

										uni.showToast({
											title: '兑换成功'
										})
										setTimeout(function() {
											uni.reLaunch({
												url: '/gc_school/pages/jifen/my'
											})
										}, 1500)
									},
									fail: function(res) {
										console.log(res, '---11--');
										console.log('取消支付')
										that.tips.tips('取消支付')
									}
								});





							} else {
								uni.showToast({
									title: res.msg,
									icon: 'none'
								})
							}

						}

					}, true)
				} else {
					uni.showToast({
						title: '请先登录'
					})
					setTimeout(function() {
						uni.reLaunch({
							url: '/gc_school/pages/user/index'
						})
					}, 1500)
				}
			},
			duihuan: function() {
				var that = this
				if (this.userinfo) {
					if (this.userinfo.integral < this.data.integral) {
						uni.showToast({
							title: '积分不足',
							icon: 'none'
						})
					} else {
						uni.showModal({
							title: '确认兑换',
							content: '兑换此商品需要' + that.data.integral + '积分,确认兑换吗?',
							complete(res) {
								console.log(res)
								// var that = this
								if (res.confirm) {
									app.globalData.util.request({

										url: 'Knowledgeorder/add',
										data: {
											s_id: uni.getStorageSync('schoolId'),
											id: that.id
										},
										success(res) {
											if (res.data.status == 200) {
												uni.showToast({
													title: '兑换成功'
												})
												setTimeout(function() {
													uni.reLaunch({
														url: '/gc_school/pages/jifen/my'
													})
												}, 1500)
											} else {
												uni.showToast({
													title: res.msg,
													icon: 'none'
												})
											}

										}

									}, true)
								} else {

								}
							}
						})
					}
				} else {
					uni.showToast({
						title: '请先登录'
					})
					setTimeout(function() {
						uni.reLaunch({
							url: '/gc_school/pages/user/index'
						})
					}, 1500)
				}
			},
			getgoodinfo: function(id) {
				var that = this
				app.globalData.util.request({
					url: 'Knowledgelist/view',
					data: {
						s_id: uni.getStorageSync('schoolId'),
						id: id

					},
					success(res) {
						if (res.data.status == 200) {
							that.data = res.data.data
							console.log(123, res)
						}

					}
				}, true)
			},
			gomycard: function() {
				uni.switchTab({
					url: '/pages/center/index'
				})
			},
			getindexinfo: function() {
				var that = this
				this.$u.post('getindexinfo').then(res => {
					console.log(res)
					that.lblist = res.lblist
					that.banner = res.banner
					that.list = res.list
				})
			}
		}
	}
</script>
<style>
	page {}
</style>
<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 100rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 32rpx;
		font-weight: bold;
		color: #2b2b41;
	}

	.button-demo {
		margin-top: 80rpx;
	}

	.link-demo {
		margin-top: 80rpx;
	}
</style>